/**
 * @FileName ObjectStructure.java
 * @Package com.designMode.visitor
 * -------------------------------------
 * @function Please write description of function
 * @Date 2016-1-19 上午11:44:26
 * -------------------------------------
 * Copyright (c) 2016,顾博君 All Rights Reserved.
 */
package com.designMode.visitor;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author 顾博君
 * @ClassName ObjectStructure
 * @Date 2016-1-19 上午11:44:26
 * @Function 随机生成元素
 */
public class ObjectStructure {
    /**
     * 对象生成器，此处通过一个工程方法模拟生成
     *
     * @return
     */
    public static Element createElement() {
        Random rand = new Random();
        if (rand.nextInt(2) == 1) {
            System.out.println("创建元素1");
            return new ConcreteElement1();
        } else {
            System.out.println("创建元素2");
            return new ConcreteElement2();
        }
    }

    public static List<Element> createList(int size) {
        Random rand = new Random();
        List<Element> list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            if (rand.nextInt(100) % 2 == 1) {
                System.out.println("创建元素1");
                list.add(new ConcreteElement1());
            } else {
                System.out.println("创建元素2");
                list.add(new ConcreteElement2());
            }
        }
        return list;
    }
}
